/**
 *
 */
package com.zhuoyue.elmt.service;

import java.util.List;

import com.eit.eitsite.common.utils.StringUtils;
import com.zhuoyue.elmt.dao.FailureReportDao;
import com.zhuoyue.elmt.entity.FailureReport;
import com.zhuoyue.elmt.entity.FailureSurveyContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eit.eitsite.common.persistence.Page;
import com.eit.eitsite.common.service.CrudService;
import com.zhuoyue.elmt.entity.FailureReplacementPart;
import com.zhuoyue.elmt.dao.FailureReplacementPartDao;

/**
 * 电梯配件更换记录Service
 * @author chenhao
 * @version 2016-09-07
 */
@Service
@Transactional(readOnly = true)
public class FailureReplacementPartService extends CrudService<FailureReplacementPartDao, FailureReplacementPart> {

	@Autowired
	private FailureReportDao failureReportDao;

	public FailureReplacementPart get(String id) {
		return super.get(id);
	}
	
	public List<FailureReplacementPart> findList(FailureReplacementPart failureReplacementPart) {
		return super.findList(failureReplacementPart);
	}
	
	public Page<FailureReplacementPart> findPage(Page<FailureReplacementPart> page, FailureReplacementPart failureReplacementPart) {
		return super.findPage(page, failureReplacementPart);
	}
	
	@Transactional(readOnly = false)
	public void save(FailureReplacementPart failureReplacementPart) {
		super.save(failureReplacementPart);
	}
	
	@Transactional(readOnly = false)
	public void delete(FailureReplacementPart failureReplacementPart) {
		super.delete(failureReplacementPart);
	}

	@Transactional(readOnly = false)
	public void saveOrUpdate(FailureReport failureReport, List<FailureReplacementPart> failureReplacementParts) {
		// 更新故障报检基本情况
		failureReport.preUpdate();
		failureReportDao.update(failureReport);

		for (int i = 0; i < failureReplacementParts.size(); i++) {
			FailureReplacementPart failureReplacementPart = failureReplacementParts.get(i);
			if (StringUtils.isEmpty(failureReplacementPart.getFormId())) {
				insert(failureReplacementPart);
			} else {
				update(failureReplacementPart);
			}
		}
	}
}